package com.suishoupai.xmb.task;

import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.suishoupai.xmb.dao.CutUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class LoginFailTask {
    private static final Log LOG = LogFactory.getLog(LoginFailTask.class);
    @Autowired
    private CutUserMapper cutUserMapper;
    @Value("${user.loginFail.update.once.limit}")
    private int onceLimit;
    @Value("${user.loginFail.update.once-sleep}")
    private int onceSleepTime;

    //每天凌晨四点执行
    @Scheduled(cron = "0 0 4 * * ?")
    public void reset() {
        LOG.info("开始重置用户登录失败数量");
        int dealNum = 0;
        while ((dealNum = cutUserMapper.resetLoginFail(onceLimit)) == onceLimit) {
            LOG.info("已处理" + dealNum);
            try {
                Thread.sleep(onceSleepTime);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        LOG.info("已处理" + dealNum);
        LOG.info("已处理完重置用户登录失败数量");
    }
}
